<?php

class Tinyask_I18n_GetTextMulti
{
	/**
	 * 所有文件读写句柄
	 *
	 * @var array
	 */
	private $_handles = array();

	public function __construct($fileName)
	{
		$this->addFile($fileName);
	}

	/**
	 * 增加一个语言文件
	 *
	 * @param string $fileName
	 */
	public function addFile($fileName)
	{
		$this->_handles[] = new Tinyask_I18n_GetText($fileName, true);
	}

	/**
	 * 翻译
	 *
	 * @param string $string
	 * @return string
	 */
	public function translate($string)
	{
		foreach ($this->_handles as $handle) {
			$string = $handle->translate($string, $count);
			if($count != -1) {
				break;
			}
		}
		return $string;
	}

	/**
	 * 复数形式
	 *
	 * @param string $single
	 * @param string $plural
	 * @param integer $number
	 * @return string
	 */
	public function ngettext($single, $plural, $number)
	{
		foreach ($this->_handles as $handle) {
			$string = $handle->ngettext($single, $plural, $count);
			if($count != -1) {
				break;
			}
		}

		return $string;
	}

	/**
	 * 关闭所有句柄
	 *
	 */
	public function __destruct()
	{
		foreach ($this->_handles as $handle) {
			unset($handle);
		}
	}
}
